Skip to content

runtime: avoid stale unbuffered receive waits#2003

Merged
xushiwei merged 1 commit into
xgo-dev:mainfrom
zhouguangyuan0718:main-debug-etcd
Jul 4, 2026
Merged

runtime: avoid stale unbuffered receive waits#2003
xushiwei merged 1 commit into
xgo-dev:mainfrom
zhouguangyuan0718:main-debug-etcd

Conversation

@zhouguangyuan0718

Copy link
Copy Markdown
Contributor

Summary

Fix a deadlock in llgo's unbuffered channel runtime where a receive that had already completed could keep waiting if another receive on the same channel overwrote the shared receive state before the first waiter woke up.

Root Cause

The runtime used channel-level getp state to determine whether an unbuffered receive rendezvous had completed. In a sequence like select { case <-ch: ... default: ... } followed immediately by another <-ch on the same channel, the later receive could set getp back to chanHasRecv, causing the earlier completed receive to wait forever.

Changes

  • Add an unbuffered rendezvous sequence counter to runtime/internal/runtime.Chan.
  • Increment the sequence when ChanSend or ChanTrySend completes an unbuffered rendezvous.
  • Make ChanRecv and select receive completion checks use the captured sequence as well as getp.
  • Add a language-level regression test under test/select_test.go that runs with both go test and llgo test.

Validation

  • go test ./test -run '^TestSelectRecvCompletionNotOverwrittenByNextRecv$' -count=1
  • timeout 30s ./llgo test ./test -run '^TestSelectRecvCompletionNotOverwrittenByNextRecv$' -count=1
  • Verified the original etcd repro by rebuilding the etcdserver test binary with llgo and running TestPublishV3Retry; it now passes instead of hanging.

@zhouguangyuan0718 zhouguangyuan0718 changed the title [codex] runtime: avoid stale unbuffered receive waits runtime: avoid stale unbuffered receive waits Jun 30, 2026
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@zhouguangyuan0718 zhouguangyuan0718 marked this pull request as ready for review July 1, 2026 01:37
@xushiwei xushiwei merged commit 7be5c6e into xgo-dev:main Jul 4, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants